var app=getApp();
Page({
	data:{
		a:true,
    current:'device',
    totalIncome:'',
    currentItemList:null,
    date:''
	},
  timestampToTime(timestamp) {
    var date = new Date(timestamp),//时间戳为10位需*1000，时间戳为13位的话不需乘1000
    Y = date.getFullYear() + '-',
    M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-',
    D = date.getDate() + ' ',
    h = date.getHours() + ':',
    m = date.getMinutes() + ':',
    s = date.getSeconds()
                return Y + M + D + h + m + s;
  },
  current(e){
    var that=this
    if (e.currentTarget.dataset.type!==that.data.current){
      // 切换
      this.setData({
        current: e.currentTarget.dataset.type
      })
      if(that.data.current==='device'){
        console.log("发送设备收益请求")
        that.setData({
          currentItemList: null
        })
      } else if (that.data.current === 'merchant'){
        console.log("发送商户收益请求")
        that.setData({
          currentItemList: null
        })
      } else if (that.data.current === 'shop'){
        console.log("发送门店收益请求")
        that.setData({
          currentItemList: null
        })
      } else if (that.data.current === 'platform'){
        console.log("发送商城收益明细请求")
        that.setData({
          currentItemList:null
        })
        wx.request({
          url: app.globalData.data_url + '/GPD/getInvestorMerchantMallRebate.do',
          data: {
            session_id: app.globalData.sessionId
          },
          success(res) {
            var temList=res.data.imrebate
            temList.forEach(function(item,idx){
              item.date=that.timestampToTime(item.date)
            })
            that.setData({
              currentItemList:temList
            })
          }
        })
      }
    }
  },
	onLoad:function(options){
    var that=this
    that.setData({
      sessoionId: app.globalData.sessionId,
    })
    // 请求总收益
    wx.request({
      url: app.globalData.data_url + '/GPD/getInvestorMerchantMallFee.do',
      data:{
        session_id: app.globalData.sessionId
      },
      success(res){
        that.setData({
          totalIncome:res.data.imfee
        })
      }
    })
	},
	onReady:function(){
		
	},
	onShow:function(){
		
	},
	onHide:function(){
		
	},
	onUnload:function(){
		
	},
	onPullDownRefresh:function(){
		
	},
	onReachBottom:function(){
		
	}
})		